/*
 * RemoteInvocationDispatcher.java    0.0.1    Nov 3, 2009
 * 
 * Copyright (c) 2009 mentalsmash.org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * The use of the Apache License does not indicate that this project is
 * affiliated with the Apache Software Foundation.
 */
package org.mentalsmash.tazio.net.ril;

import java.io.NotSerializableException;

import org.mentalsmash.tazio.net.ril.exceptions.NoSuchRemoteMethodException;
import org.mentalsmash.tazio.net.ril.exceptions.NoSuchRemoteObjectException;
import org.mentalsmash.tazio.net.ril.exceptions.NotSerializableArgumentException;
import org.mentalsmash.tazio.net.ril.exceptions.NotSerializableOutcomeException;
import org.mentalsmash.tazio.commons.identifiers.OID;

/**
 * Class implementing this interface are responsible for providing specific
 * operations on other {@link BaseRemoteInvoker}s, these being primarily the
 * requesting of a method invocation and the retrieving of proxies to objects
 * registered on the {@link BaseRemoteInvoker}s currently available.
 * 
 * @version 0.0.1 Nov 3, 2009
 * @author Andrea Sorbini <as@mentalsmash.org>
 */
public interface RemoteInvocationDispatcher {
	/**
	 * Request a method invocation on a object identified by the supplied
	 * {@link OID} and registered on some other {@link BaseRemoteInvoker}.<br/>
	 * Notice that the all of the Objects supplied as the method's arguments
	 * need to be serializable, otherwise an exception will be thrown.<br/>
	 * Also, if the method requested hasn't been specified as 'by copy', any
	 * argument found to be also a registered instance in the local
	 * {@link RemoteObjectsRegistry} will be substituted automatically by its
	 * corresponding RemoteObject proxy, so that the instance on which the
	 * method is called will be able to call methods back on this host.
	 * 
	 * @param oid
	 *            an OID identifying a remote instance
	 * @param method
	 *            a {@link RemoteMethod} instance describing the method to
	 *            invoke
	 * @param args
	 *            an array of arguments for the method to invoke.
	 * @return the result of the method's invocation or the exception it raised.
	 * @throws NoSuchRemoteObjectException
	 *             if no remote instance was found with the supplied OID
	 * @throws NoSuchRemoteMethodException
	 *             if the supplied RemoteMethod is not implemented by the
	 *             identified remote instance
	 * @throws NotSerializableException
	 *             if any of the method invocation's arguments weren't
	 *             serializable
	 */
	public Object invokeRemoteMethod(OID oid, RemoteMethod method, Object[] args)
			throws NoSuchRemoteObjectException, NoSuchRemoteMethodException,
			NotSerializableArgumentException, NotSerializableOutcomeException;

	/**
	 * Retrieves a proxy to a remote instance registered with the supplied OID
	 * on some other RemoteInvoker.
	 * 
	 * @param oid
	 *            an OID identifying a remote instance
	 * @return a RemoteObject instance that might be used as a proxy to
	 *         seamlessly invoke methods on the requested remote instance
	 * @throws NoSuchRemoteObjectException
	 *             if no remote instance was found for the supplied OID
	 */
	public RemoteObject getRemoteObject(OID oid)
			throws NoSuchRemoteObjectException;

	// /**
	// * Sets the RemoteInvoker this RemoteInvocationDispatcher is currently
	// working with.
	// * @param invoker
	// */
	// void setRemoteInvoker(RemoteInvoker invoker);
}
